package org.feng.navigation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动器
 *
 * @author junzi
 */
@Slf4j
@EnableAspectJAutoProxy(exposeProxy = true)
@SpringBootApplication
@EnableDiscoveryClient
@ConfigurationPropertiesScan("org.feng.navigation")
@RefreshScope
public class Application {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
        Environment env = application.getEnvironment();
        String contextPath = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}{}\n\t" +
                        "External: \thttp://{}:{}{}\n\t" +
                        "Doc: \thttp://{}:{}{}/doc.html\n\t" +
                        "Actuator: \thttp://{}:{}{}/actuator\n\t" +
                        "Prometheus Actuator: \thttp://{}:{}{}/actuator/prometheus\n\t" +
                        "NacosConfig Actuator: \thttp://{}:{}{}/actuator/nacosconfig\n\t" +
                        "Main Page：\thttp://localhost:{}{}/index.html\n\t" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                env.getProperty("server.port"), contextPath
                );
    }
}
